package controller.cartp;

import com.alibaba.fastjson.JSON;
import com.zuche.framework.tradingPlatform.CurrenceSource;
import com.zuche.framework.tradingPlatform.GroupType;
import com.zuche.framework.tradingPlatform.RequestParams;
import com.zuche.framework.utils.PropertiesReader;
import controller.constant.CarTpConstant;
import controller.enums.GroupTypeEnum;
import controller.remote.CartpRemoteClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by 雷霆 on 2016/10/25.
 */
@Controller
@RequestMapping(value = "kuaiqian/",produces = "text/html;charset=utf-8")
public class KuaiqianController2 {
    private String projectAddress;
    private static final Logger logger = LoggerFactory.getLogger(UnionPayRPCTestController.class);

    public KuaiqianController2() {
        this.projectAddress = PropertiesReader.getAppointPropertiesAttribute(
                "setting", "projectAddress", String.class);
    }


    @RequestMapping(value = "doQueryCardInfo.do_")
    public static  Object doQueryCardInfo(){
        Map<String,String> requestMap=new HashMap<String, String>();
        requestMap.put(RequestParams.SYS_GROUP, CarTpConstant.SYS_GROUP_UCAR);
        requestMap.put(RequestParams.GROUP_TYPE, GroupType.QUERY_CARD_INFO);
        requestMap.put(RequestParams.CARD_NO, "6225768719356568");


        logger.error(" [carttp调用参数] : " + JSON.toJSONString(requestMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(requestMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));

        return resultMap;
    }


    @RequestMapping(value = "doEposReQuickPay.do_")
    public static  Object doEposReQuickPay(){
        Map<String,String> requestMap=new HashMap<String, String>();
        requestMap.put(RequestParams.SYS_GROUP, CarTpConstant.SYS_GROUP_UCAR);
        requestMap.put(RequestParams.SOURCE_ID, CarTpConstant.SOURCE_ID);
        requestMap.put(RequestParams.GROUP_TYPE, GroupType.EPOS_REQUICK_PAY);
        requestMap.put(RequestParams.BUSINESS_NAME,"eposPay");
        requestMap.put(RequestParams.BUSINESS_ID,"DJP2257575203316");
        requestMap.put(RequestParams.VALID_CODE, "995672");
        requestMap.put(RequestParams.VALID_CODE, "995672");
        requestMap.put(RequestParams.CARD_TYPE, "2");
        requestMap.put(RequestParams.RECORD_ID, "03127335344442063");
        requestMap.put(RequestParams.BUSINESS_MONEY, "1.0");
        requestMap.put(RequestParams.PAYER_ID, "5101466");
        requestMap.put(RequestParams.ASYNC_REPLY_URL, "http://mapiproxytest03.10101111.com:9080/resource/m/ucar/cdms/pay/callback");
        requestMap.put(RequestParams.IDENTITY_TYPE, "0");
        requestMap.put(RequestParams.DIRECT_CARD, "0");
        requestMap.put(RequestParams.BIND_ID, "33726");
        requestMap.put("tp_is_autopay", "2");
        requestMap.put("tp_is_autopay", "2");


        logger.error(" [carttp调用参数] : " + JSON.toJSONString(requestMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(requestMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));

        return resultMap;
    }



    //快捷再次支付短信
    @RequestMapping("/kqQuickPaySms2.do_")
    public void testQuickPaySms2(HttpServletRequest request,
                                 HttpServletResponse response) {
        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put(RequestParams.ASYNC_REPLY_URL, projectAddress
                + "/rpcReturn.do_");
        paramMap.put(RequestParams.GROUP_TYPE, "unionSendSms");
        paramMap.put(RequestParams.PAYER_ID,"5101466");//
        paramMap.put(RequestParams.BIND_ID, "33726");//33634,33633
        paramMap.put(RequestParams.SOURCE_ID, CurrenceSource.ABC);//33634,33633
        paramMap.put(RequestParams.BUSINESS_MONEY, "1");
        paramMap.put(RequestParams.BUSINESS_ID, ""+System.currentTimeMillis());
        paramMap.put(RequestParams.BUSINESS_NAME, "ucarcdms");
        paramMap.put(RequestParams.SYS_GROUP,"1");//支付账户
        paramMap.put(RequestParams.IS_TEST, "TRUE");
        paramMap.put(RequestParams.CARD_NO, "4367420061070282739");
        logger.error(" [carttp调用参数] : " + JSON.toJSONString(paramMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(paramMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));    }

    //快捷在次支付
    @RequestMapping("/kqEposSecQuickPay.do_")
    public void testEposSecQuickPay(HttpServletRequest request) {
        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put(RequestParams.ASYNC_REPLY_URL,"http://mapiproxytest03.10101111.com:9080/resource/m/ucar/cdms/pay/callback");
        paramMap.put(RequestParams.GROUP_TYPE, "unionSmsPay");
        paramMap.put(RequestParams.PAYER_ID,"5101466");//
        paramMap.put(RequestParams.BIND_ID, "33726");//33634,33633
        paramMap.put(RequestParams.BUSINESS_MONEY, "1");
        paramMap.put(RequestParams.BUSINESS_ID, "03127335412557030");
        paramMap.put(RequestParams.BUSINESS_NAME, "ucarcdms");
        paramMap.put(RequestParams.SYS_GROUP,"1");

        paramMap.put(RequestParams.VALID_CODE,"907184");
        paramMap.put(RequestParams.TOKEN, "487717019");
            paramMap.put(RequestParams.RECORD_ID,"03127335412557545");
        logger.error(" [carttp调用参数] : " + JSON.toJSONString(paramMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(paramMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));
    }


    //快捷在次支付
    @RequestMapping("/pageCreditCardBindRemoteService.do_")
    public void pageCreditCardBindRemoteService(HttpServletRequest request) {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("defaultOrder", "modifyTime desc");
        param.put("startIndex", 0);
        param.put("endIndex", 10);
        param.put("sourceId", null); // 银行名称
        param.put("identityCard","130984198904271527");// 身份证号
        //param.put("cardNoDec", "4581231213585326");// 银行卡号
        param.put("payerId", null);
        Map<String,Object> resultMap = CartpRemoteClient.doRemote(param);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));
    }

    /**
     * 信用卡发短信
     * @param request
     * @param response
     * @throws java.io.IOException
     */
    @RequestMapping("/kqcreateNoSms.do_")
    public void createNoSms(HttpServletRequest request,
                            HttpServletResponse response) throws IOException {
        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put(RequestParams.ASYNC_REPLY_URL, "http://127.0.0.1:9080/cartptest/test/testRpcModeReturn.do_");

        paramMap.put(RequestParams.GROUP_TYPE, GroupType.CREATE_NO_SMS);
        paramMap.put(RequestParams.BUSINESS_MONEY,"0.01");

        paramMap.put(RequestParams.CARD_TYPE,"1");
        paramMap.put(RequestParams.SOURCE_ID, CurrenceSource.SPDB);
        paramMap.put(RequestParams.SYS_GROUP, CarTpConstant.SYS_GROUP_UCAR);

        paramMap.put(RequestParams.PAYER_ID, "5105151");
        paramMap.put(RequestParams.PAYER_NAME, "雷霆");
        paramMap.put(RequestParams.CARD_NO, "6217920660398566");
        paramMap.put(RequestParams.CARD_TYPE, "2");
        paramMap.put(RequestParams.CREDITCARD_EXPIREMONTH, "12");
        paramMap.put(RequestParams.CREDITCARD_EXPIREYEAR, "24");
        paramMap.put(RequestParams.CREDITCARD_CVV, "423");
        paramMap.put(RequestParams.PAYER_TEL, "15301067848");
        paramMap.put(RequestParams.IDENTITY_ID, "652323199107043516");
        paramMap.put(RequestParams.IDENTITY_TYPE, "0");
        paramMap.put("tp_is_autopay", "1");

        paramMap.put(RequestParams.IDENTITY_TYPE,"0");
        paramMap.put(RequestParams.NATION_CODE, "156");

        paramMap.put(RequestParams.IS_VALIDATE, "true");
        logger.error(" [carttp调用参数] : " + JSON.toJSONString(paramMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(paramMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));
    }

    /**
     * 储蓄卡快捷支付
     * @param request
     * @param response
     */
    @RequestMapping("/kqEposPaySms.do_")//
    public void kqEposPaySms(HttpServletRequest request,
                                HttpServletResponse response) {
        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put(RequestParams.ASYNC_REPLY_URL, projectAddress
                + "/rpcReturn.do_");
        paramMap.put(RequestParams.GROUP_TYPE, GroupType.EPOS_AUTH_FREEZE);
        paramMap.put(RequestParams.VALID_CODE, "091945");
        paramMap.put(RequestParams.TOKEN, "503338022");
        paramMap.put(RequestParams.BUSINESS_ID  , "1");
        paramMap.put(RequestParams.BUSINESS_NAME, "1");
        paramMap.put(RequestParams.BUSINESS_MONEY, "1");
        paramMap.put(RequestParams.RECORD_ID, "03127344713206610");

        //专车区分是 1:首页绑卡,还是2:充值页面绑卡（租车不传）
        paramMap.put("tp_is_autopay","1");
        paramMap.put(RequestParams.IS_VALIDATE,"1");//是否需要绑卡
        paramMap.put(RequestParams.SOURCE_ID, CurrenceSource.SPDB);
        paramMap.put(RequestParams.SYS_GROUP, CarTpConstant.SYS_GROUP_UCAR);

        paramMap.put(RequestParams.PAYER_ID, "15981030");
        paramMap.put(RequestParams.PAYER_NAME, "雷霆");
        paramMap.put(RequestParams.CARD_NO, "6217920660398566");
        paramMap.put(RequestParams.CARD_TYPE, "2");
        paramMap.put(RequestParams.CREDITCARD_EXPIREMONTH, "12");
        paramMap.put(RequestParams.CREDITCARD_EXPIREYEAR, "24");
        paramMap.put(RequestParams.CREDITCARD_CVV, "423");
        paramMap.put(RequestParams.PAYER_TEL, "15301067848");
        paramMap.put(RequestParams.IDENTITY_ID, "652323199107043516");
        paramMap.put(RequestParams.IDENTITY_TYPE, "0");


        logger.error(" [carttp调用参数] : " + JSON.toJSONString(paramMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(paramMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));
    }


    @RequestMapping(value = "doAuth.do_")
    public static  Object doAuth(){
        Map<String,String> requestMap=new HashMap<String, String>();
        requestMap.put(RequestParams.SYS_GROUP, CarTpConstant.SYS_GROUP_UCAR);
        requestMap.put(RequestParams.SOURCE_ID, CarTpConstant.SOURCE_ID);
        requestMap.put(RequestParams.GROUP_TYPE, GroupType.EPOS_AUTH_SMS);
        requestMap.put(RequestParams.BUSINESS_NAME,"ucarcdms");
        requestMap.put(RequestParams.BUSINESS_ID, "27343434474517");
        requestMap.put(RequestParams.BUSINESS_MONEY,"1");
        requestMap.put(RequestParams.ASYNC_REPLY_URL,"http://cdmstest.10101111.com/ucarcdms/bankcard/undoPreAuthorizationCallBack.do");
        requestMap.put(RequestParams.PAYER_ID, "5125131_1788");
        requestMap.put(RequestParams.BIND_ID, "34146");

        logger.error(" [carttp调用参数] : " + JSON.toJSONString(requestMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(requestMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));

        return resultMap;
    }

    /**
     * 预授权撤销
     * @param request
     * @param response
     */
    @RequestMapping("/testAuthCancel.do_")//
    public void testAuthCancel(HttpServletRequest request,
                             HttpServletResponse response) {
        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put(RequestParams.ASYNC_REPLY_URL,"http://cdms.10101111.com/ucarcdms/bankcard/undoPreAuthorizationCallBack.do");
        paramMap.put(RequestParams.GROUP_TYPE, GroupType.EPOS_AUTH_CANCEL);
        paramMap.put(RequestParams.RECORD_ID, "11127352370377620");
        paramMap.put(RequestParams.BUSINESS_ID, "27352372026427");
        paramMap.put(RequestParams.SYS_GROUP, CarTpConstant.SYS_GROUP_UCAR);

        paramMap.put(RequestParams.IDENTITY_TYPE, "0");


        logger.error(" [carttp调用参数] : " + JSON.toJSONString(paramMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(paramMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));
    }

    public  void xx1(){

    }
}
